package com.xebia.pomodoro
{
	import com.xebia.pomodoro.enums.PomodoroStatus;
	import com.xebia.pomodoro.sound.PlaySound;

	import flash.events.Event;
	import flash.events.TimerEvent;

	[Bindable]
	public class Pomodoro
	{
		public var status:Number;

		public var timer:MinuteTimer;

		public var totalTimeInSeconds:Number;

		public var secondsLeft:Number;

		public function Pomodoro()
		{
			status = PomodoroStatus.NOTSTARTED;
		}

		public function startPomodoro(minutes:Number):void
		{
			secondsLeft = totalTimeInSeconds = minutes * 60;
			timer = new MinuteTimer(minutes);
			timer.addEventListener(TimerEvent.TIMER, onTimer);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
			status = PomodoroStatus.INPROGRESS;
			timer.start();
		}

		public function stopPomodoro():void
		{
			timer.stop();
			status = PomodoroStatus.NOTSTARTED;
		}

		public function onTimer(event:TimerEvent):void
		{
			secondsLeft = secondsLeft - 1;

		}

		public function onTimerComplete(event:TimerEvent):void
		{
			new PlaySound();
			status = PomodoroStatus.NOTSTARTED;

		}

	}
}
